package com.weiawei.Dialog;

import com.weiawei.Model.Chess;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class ChooseRoleDialog extends baseDialog {
    private JButton blackButton, whiteButton;
    private JLabel jLabel;

    /**
     * ChooseRoleDialog的构造函数
     *
     * @param jFrame
     * @param title  对话框标题
     * @param b
     */
    public ChooseRoleDialog(JFrame jFrame, String title, boolean b) {
        super(jFrame, title, b);
        this.init();
    }

    /**
     * 初始化执棋选择对话框
     * 初始化内容包括选项与内容
     */
    private void init() {
        blackButton = new JButton("黑棋");
        whiteButton = new JButton("白棋");
        jLabel = new JLabel("请选择执棋颜色");
        message = 1;


        this.setLeftButton(whiteButton);
        this.setRightButton(blackButton);


        jLabel.setFont(new Font(Font.DIALOG_INPUT, Font.BOLD, 15));
        jLabel.setBounds(80, 10, 200, 100);

        add(blackButton);
        add(whiteButton);
        add(jLabel);
    }

    /**
     * 通过用户点击的按键来相应不同的事件
     * 当用户点击黑棋时执棋为黑
     * 当用户点击白棋时执棋为白
     *
     * @param e 用户点击的按键
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == blackButton) {
            message = Chess.black;
            setVisible(false);
        } else if (e.getSource() == whiteButton) {
            message = Chess.white;
            setVisible(false);
        }
    }
}
